package com.qiqi.service.fee.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qiqi.dao.CatalogMapper;
import com.qiqi.dao.FeeMapper;
import com.qiqi.domain.Catalog;
import com.qiqi.domain.CatalogExample;
import com.qiqi.domain.Fee;
import com.qiqi.domain.FeeExample;
import com.qiqi.service.fee.FeeService;
import com.qiqi.web.vo.CatalogAndFee;
@Service("feeService")
public class FeeServiceImpl implements FeeService{
	@Autowired
	private CatalogMapper catalogMapper;
	@Autowired
	private FeeMapper feeMapper;
	
	private static Date update;
	private static List<CatalogAndFee> cfs;
	private static long timeout=60*60*60*1000;
	
	public List<CatalogAndFee> getAllFees() {
		CatalogExample queryCatalog=new CatalogExample();
		//套餐信息
		List<Catalog> catalogs = catalogMapper.selectByExample(queryCatalog);
		Date now=new Date();
		if(update==null||now.getTime()-update.getTime()>timeout){
			cfs=new ArrayList<CatalogAndFee>();
			update=now;
			CatalogAndFee cf = null;
			for (Catalog cg : catalogs) {
				cf = new CatalogAndFee();
				cf.setCatalog(cg);
				FeeExample queryFee = new FeeExample();
				queryFee.createCriteria().andCidEqualTo(cg.getId());
				List<Fee> fees = feeMapper.selectByExample(queryFee);
				cf.setFees(fees);
				cfs.add(cf);
			}
		}
		return cfs;
	}

}
